// pages/house/RentalHouseDetail/com/form-track/form-track.js
import api from '../../../../../common/api'

Component({
  /**
   * 组件的配置
   */
  options: {
    styleIsolation: 'isolated',
    pureDataPattern: /^_/
  },

  /**
   * 组件的属性列表
   */
  properties: {
    delId: {
      type: String,
      value: ''
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    _value: '',
  },

  /**
   * 组件的数据监听
   */
  observers: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onInput(e) {
      this.data._value = e.detail.value
    },

    onCancel() {
      this.triggerEvent('cancel')
    },

    onConfirm() {
      const {
        _value
      } = this.data
      if (!(_value && _value.trim())) {
        wx.showToast({
          icon: 'none',
          title: '备注不能为空',
        })
        return
      }
      this.saveHouseTrack(_value)
    },

    async saveHouseTrack(content) {
      const {
        delId
      } = this.data
      const res = await api.saveHouseTrack({
        hmDelId: delId,
        houseTrackContent: content,
        // houseTrackTitle: ''
      })
      if (res && res.data && res.data.isSuccess) {
        wx.showToast({
          icon: 'none',
          title: '添加成功',
        })
        this.triggerEvent('confirm')
      } else {
        wx.showToast({
          icon: 'none',
          title: '添加失败,请稍后再试',
        })
      }
    },

    onMove() {
      return false
    }

  }



})